package com.xuanwei.core.mq;

import com.alibaba.fastjson.JSON;
import com.xuanwei.xwcommon.consts.MqType;
import com.xuanwei.xwcommon.entity.dto.MessageDto;
import com.xuanwei.xwcommon.enums.MqHandlerType;
import lombok.Data;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

@Component
@Data
public class SendProduct {

    private AmqpTemplate amqpTemplate;



    public SendProduct(AmqpTemplate amqpTemplate) {
        this.amqpTemplate = amqpTemplate;
    }

    public void update(Integer id){
        MessageDto<Integer> dto =new MessageDto<>();
        dto.setType(MqHandlerType.UPDATE);
        dto.setData(id);
        amqpTemplate.convertAndSend(MqType.PRODUCT,JSON.toJSONString(dto));
    }

    public void delete(Integer id){
        MessageDto<Integer> dto =new MessageDto<>();
        dto.setType(MqHandlerType.DELETE);
        dto.setData(id);
        amqpTemplate.convertAndSend(MqType.PRODUCT,JSON.toJSONString(dto));
    }
}
